package com.itheima.config;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import com.itheima.bean.Employee;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;

import javax.servlet.http.HttpSession;
import java.time.LocalDateTime;

@Configuration
public class MyMetaObjectHandler implements MetaObjectHandler {
    @Autowired
    private HttpSession session;

    @Override
    public void insertFill(MetaObject metaObject) {
//        Employee employee = (Employee)session.getAttribute("employee");

        metaObject.setValue("createTime", LocalDateTime.now());
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("createUser",ThreadLocalConfig.get());
        metaObject.setValue("updateUser",ThreadLocalConfig.get());

    }

    @Override
    public void updateFill(MetaObject metaObject) {
//        Employee employee = (Employee)session.getAttribute("employee");
        metaObject.setValue("updateTime",LocalDateTime.now());
        metaObject.setValue("updateUser",ThreadLocalConfig.get());
    }
}
